#include <iostream>
#include <string>
#include <vector>
using namespace std;
vector<string> findOcurrences(string text, string first, string second)
{
    text.push_back(' ');
    vector<string> res;
    vector<string> temp;
    string tempstring;
    for (int i = 0; i < text.size(); ++i) {
	if (text[i] == ' ') {
	    temp.push_back(tempstring);
	    tempstring.clear();
	} else {
	    tempstring.push_back(text[i]);
	}
    }

    int pointer = 0;
    while (pointer < temp.size() - 2) {
	if (temp[pointer] == first && temp[pointer + 1] == second) {
	    res.push_back(temp[pointer + 2]);
	}
	++pointer;
    }
    return res;
}

int main(int argc, char* argv[])
{
    string text = "jkypmsxd jkypmsxd kcyxdfnoa jkypmsxd kcyxdfnoa jkypmsxd kcyxdfnoa kcyxdfnoa jkypmsxd kcyxdfnoa";
    string first = "kcyxdfnoa";
    string second = "jkypmsxd";
    auto p = findOcurrences(text, first, second);
    for (int i = 0; i < p.size(); ++i) {
	cout << p[i].data() << endl;
    }
    return 0;
}
